<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">部门管理</h1>
</div>

<div class="wrapper-md"  >
  <div class="panel panel-default">
    <div ng-controller="infoEditCtrl">
      <div class="row">  
        <div class="col-sm-12" >
          <form name="form-contact" ng-submit="processForm()" class="form-horizontal">
          <div class="panel-heading">
            <span class="h4">
            <button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>
            </span>
          </div>
            <div class="panel-body">
              <div class="panel-heading">
                <span class="h4" style="color: blue;">栏目简介信息</span>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">父级栏目</label>
                <div class="col-sm-5">
                  <select class="form-control " ng-model="contact.FatherId"  required >
                    <option ng-repeat="x in fathers" value="{{x.key}}">{{x.value}}</option>
                  </select>
                </div>
              </div>
                <div class="line line-dashed b-b line-lg pull-in"></div>

                <div class="form-group">
                  <label class="col-sm-1 control-label">栏目名称</label>
                  <div class="col-sm-5">
                    <input type="text" class="form-control" placeholder="菜单名称" ng-model="contact.ClassName" required >
                  </div>
                </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>
                <div class="form-group">
                  <label  class="col-sm-1 control-label">排序</label>
                    <div class="col-sm-5">
                      <input type="Number" class="form-control"  ng-model="contact.ClassDisplayOrder" required >
                    </div>
                </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>


                <div class="form-group">
                  <label class="col-sm-1 control-label">备注</label>  
                  <div class="col-sm-10">
                  <textarea class="form-control" ng-model="contact.ClassRemark" rows="6" placeholder="备注">{{contact.ClassRemark}}</textarea>
                  </div>
                </div>
                <div class="line line-dashed b-b line-lg pull-in"></div>

                <div class="form-group">
                  <label class="col-sm-1 control-label">图标</label>  
                  <div class="col-sm-5">
                    <input type="text" class="form-control" placeholder="" ng-model="contact.ClassSmallIcon" >
                  </div>
                </div>
            </div>
            <div class="panel-body">
              <div class="panel-heading">
                <span class="h4" style="color: blue;">配置信息</span>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">启用/停用</label>
                <div class="col-sm-1">
                  <label class="i-switch m-t-xs m-r">
                    <input type="checkbox" id="check" ng-model="ClassIsDisplay" >
                        <i></i>
                  </label>
                </div>
              </div>
              <div class="line line-dashed b-b line-lg pull-in"></div>


  <!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="contact.ClassUuid"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'"  >
    <!--隐藏字段-->

            </div>


            <footer class="panel-footer text-right bg-light lter">
              <button type="submit" class="btn btn-success">提交</button>
            </footer>
          </div>
        </form>
      </div>
    </div>
   
</div>
</div>




</div>


<!--angularjs-->
<script type="text/javascript">

  'use strict';
app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {

  var fatherDatas = [{key : "0", value : "顶级菜单"}];

  var getInfoUrl = API_URL+"user_class?query=delflag:0"    

  var fatherDBs=  MY_ASYNC_AJAX(getInfoUrl);

  for(var i=0;i<fatherDBs.length;i++){
    var classDataId = fatherDBs[i].Id+"";
    var classDataName = fatherDBs[i].ClassName+"";
    var classData = {key : classDataId, value :  classDataName};
    fatherDatas.push(classData);
  }
 $scope.fathers = fatherDatas;



//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.back();
    };
//返回按钮：结束
    var infoId = $stateParams.infoId;
    console.log('获取路由参数infoId：'+infoId);


 //如果infoId不为空，查询详情：开始
  if(''!=infoId){
      var getInfoUrl = API_URL+"user_class?query=delflag:0,Id:"+infoId;    

    $http.get(getInfoUrl).success(function (response) {
         var obj = response[0];
           obj.ClassDisplayOrder = Number(obj.ClassDisplayOrder);
            if("0" == obj.ClassIsDisplay||obj.ClassIsDisplay==''){
              $scope.ClassIsDisplay = false;
             }else {
               $scope.ClassIsDisplay = true;
             }

           $scope.contact = obj;

           console.log(JSON.stringify($scope.contact));

      });
  }
//如果infoId不为空，查询详情：结束


  //表单提交开始
$scope.processForm= function (){
 
  //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"user_class";
var formData =  $scope.contact;

  //1.参数处理
    formData.AddTime = getNowDBFormatDate();
    formData.UpdateTime = getNowDBFormatDate();
    formData.AdderId = 1;
    formData.AdderName = '1';
    formData.UpdaterId = 1;
    formData.UpdaterName = '1';
    formData.ClassUuid='';
    formData.ClassDisplayOrder=formData.ClassDisplayOrder + '';
    formData.FatherId = Number(formData.FatherId);

 
    console.log(JSON.stringify(formData));
  if("undefined"!=typeof(formData.Id)){

          $.ajax({  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                  top.layer.msg('保存成功', {icon: 6});
                  //2.成功跳转页面
                  $state.go('app.user.department');
                  }  
             }); 
              }else{

           $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.user.department');
                  }  
             }); 

  }
}

});
</script>
<!--angularjs-->
